package top.leyi.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import top.leyi.entity.ObjRedisTemplate;
import top.leyi.utils.RedisObjectSerializer;

@Configuration
public class RedisConfig {
    ////配置ioc bean(需实现序列化接口)，注入序列化方法方法
    @Bean
    public ObjRedisTemplate redisTemplate(RedisConnectionFactory factory) {

        ObjRedisTemplate  template = new ObjRedisTemplate ();
        template.setConnectionFactory(factory);
        template.setKeySerializer(new StringRedisSerializer());
        template.setHashKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(new RedisObjectSerializer());
        return template;

    }
}